package com.test.javafaq_kafka.vo;

import com.google.gson.Gson;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class DemoConsumer {

    Gson gson = new Gson();

    //@KafkaListener会监听"myTopic"话题的变化
    //当这个话题有新的消息时，就会自动调用这个注解的方法去处理；

    @KafkaListener(topics = {"myTopic"})
    public void revive(ConsumerRecord<String,String> record){

        String json = record.value();
        log.debug("接收到:{}",json);
        DemoMessage msg = gson.fromJson(json, DemoMessage.class);
        log.debug("message:{}",msg);
    }
}
